<%@page import="com.alibaba.fastjson.JSONObject"%>
<%@page import="pers.rcklos.myserver.entity.PaperItem"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	int page_num = (int)request.getAttribute("page") + 1;
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Admin</title>
	<link rel="stylesheet" type="text/css" charset="utf-8" href="../static/css/admin.css?v=<%= System.currentTimeMillis()%>"/>
	<link rel="stylesheet" type="text/css" charset="utf-8" href="../static/css/reset.css?v=<%= System.currentTimeMillis()%>"/>
	<script src="../static/js/jquery.js"></script>
</head>
<body>
<div class="header clear-both">
			<div class="icon-sp">
				<h1>后台管理系统</h1>
			</div>
			<div class="header-nav clear-both">
				<ul>
					<li>测试</li>
					<li>测试</li>
					<li><a class="logout" href="../user/login">注销</a></li>
				</ul>
			</div>
		</div>
		<div class="main-container">
			<div class="aside-bar scroll">
				<a href="#">
					<span class="icon icon-peach">VISUAL ADMIN</span>
					<img style="width: 100%; display: block;" src="../static/images/img-clinet-nav.jpg" alt="图片">
				</a>
				<ul>
					<li class="<%=(request.getAttribute("thead") == null || (request.getAttribute("thead") != null &&(int)request.getAttribute("thead") == 0))?"li-active": ""%>"><a href="../user/query_all">用户管理</a></li>
					<li class="<%=(request.getAttribute("thead") != null &&(int)request.getAttribute("thead") == 1)?"li-active":"" %>"><a href="../paper/query_all">纸条管理</a></li>
					<li class="<%=(request.getAttribute("thead") != null &&(int)request.getAttribute("thead") == 2)?"li-active":"" %>"><a href="../comment/query_all">评论管理</a></li>
					<li class="<%=(request.getAttribute("thead") != null &&(int)request.getAttribute("thead") == 3)?"li-active":"" %>"><a href="#">系统管理</a></li>
				</ul>
			</div>
			<div class="main-view">
				<div class="user-table main-table">
					<table class="card-box">
					<c:set var="thead" value="${requestScope.thead }" />
					<c:if test="${thead == 0}">		<!-- 用户表  -->
						<thead>
							<tr>
								<th width="80px">id</th>
								<th width="140px">名称</th>
								<th width="170px">密码</th>
								<th width="120px">昵称</th>
								<th width="140px">电话</th>
								<th width="150px">邮箱</th>
								<th width="100px">学校id</th>
								<th width="120px">学生认证</th>
								<th width="170px">注册时间</th>
								<th width="170px">最近登录</th>
								<th width="80px">操作1</th>
								<th width="80px">操作2</th>
							</tr>
						</thead>	
						<tbody>
							<c:forEach var="user" items="${requestScope.users}">
								<tr>
									<td>${user.uid}</td>
									<td>${user.userName}</td>
									<td>${user.userPassword }</td>
									<td>${user.userNickName }</td>
									<td>${user.userPhone }</td>
									<td>${user.userEmail }</td>
									<td>0</td>
									<td>true</td>
									<td>${user.createTime }</td>
									<td>${user.lastLoginTime }</td>
									<td><a class="btn-modify" href="./modify?uid=${user.uid}">修改</a></td>
									<td><button class="btn-delete" onclick="deleteUser(${user.uid})" >删除</button></td>
								</tr>
							</c:forEach>
						</tbody>
					</c:if>
					<c:if test="${thead == 1}">		<!-- 纸条表  -->
						<thead>
							<tr>
								<th width="80px">id</th>
								<th width="140px">楼主</th>
								<th width="140px">标题</th>
								<th width="180px">内容</th>
								<th width="80px">接收量</th>
								<th width="80px">可接收量</th>
								<th width="140px">地址</th>
								<th width="80px">可见性</th>
								<th width="80px">点赞量</th>
								<th width="80px">推荐量</th>
								<th width="170px">发表日期</th>
								<th width="80px">操作1</th>
								<th width="80px">操作2</th>
							</tr>
						</thead>	
						<tbody>
							<c:forEach var="paper" items="${requestScope.papers}">
								<tr>
									<td>${paper.paperId}</td>
									<td>${paper.userId}</td>
									<td>${paper.title }</td>
									<td>${paper.content }</td>
									<td>${paper.numReceiver }</td>
									<td>${paper.maxReceiver }</td>
									<td>${paper.addr }</td>
									<td>${paper.visibleString}</td>
									<td>${paper.numCommend }</td>
									<td>${paper.numComment }</td>
									<td>${paper.createTime }</td>
									<td><button class="btn-modify">修改</button></td>
									<td><button onclick="deletePaper(${paper.paperId})" class="btn-delete">删除</button></td>
								</tr>
							</c:forEach>
						</tbody>
					</c:if>
					<c:if test="${thead == 2}">		<!-- 评论表表  -->
						<thead>
							<tr>
								<th width="80px">id</th>
								<th width="80px">发送者id</th>
								<th width="80px">接收者id</th>
								<th width="80px">纸条id</th>
								<th width="80px">评论id</th>
								<th width="170px">评论内容</th>
								<th width="140px">地址</th>
								<th width="80px">可见性</th>
								<th width="80px">点赞量</th>
								<th width="80px">推荐量</th>
								<th width="140px">发表日期</th>
								<th width="140px">修改日期</th>
								<th width="80px">操作1</th>
								<th width="80px">操作2</th>
							</tr>
						</thead>	
						<tbody>
							<c:forEach var="comment" items="${requestScope.comments}">
								<tr>
									<td>${comment.commId }</td>
									<td>${comment.userId }</td>
									<td>${comment.toUser }</td>
									<td>${comment.paperId }</td>
									<td>${comment.toCommId==null?comment.toCommId:0 }</td>
									<td>${comment.comment }</td>
									<td>${comment.addr }</td>
									<td>${comment.visibleString }</td>
									<td>${comment.numCommend }</td>
									<td>${comment.numComment }</td>
									<td>${comment.createTime }</td>
									<td>${comment.modifyTime }</td>
									<td><button class="btn-modify">修改</button></td>
									<td><button class="btn-delete" onclick="deleteComment(${comment.commId})">删除</button></td>
								</tr>
							</c:forEach>
						</tbody>
					</c:if>
					</table>
					<div class="page-box">
						<c:if test="${ page > 0 }">
							<a style="display: inline-block; color: blue;" href="./query_all?start=${ page - 1 }">上一页</a>
						</c:if>
						现在是第<%=page_num%>页
						<c:if test="${ query_size == 10 }">
							<a style="display: inline-block; color: blue;" href="./query_all?start=${ page + 1 }">下一页</a>
						</c:if>
					</div>
				</div>
			</div>
		</div>
		<div class="footer"></div>
</body>
<script type="text/javascript">
// 这里写的是效果
$('.aside-bar ul li').on('click', function(){
	if(!$(this).hasClass('li-active'))
		switchView($(this));
});

function switchNav(index){
	var view = $('.aside-bar ul li').eq(index);
	view.addClass('li-active');
	view.siblings().removeClass('li-active');
}

function switchView(view){
	switchNav(view.index());
}

function deleteUser(uid){
	$.ajax({
		url: './delete?uid=' + uid,
		success: function(res){
			let delete_object = JSON.parse(res);
			alert(delete_object.state);
			location.reload();
		}
	});
}

function deletePaper(paper_id) {
	$.ajax({
		url: './delete?pid=' + paper_id, // generateURL(2, 'delete', 'comm_id=' + comm_id), // 2 是 comment
		success: function(res){
			alert(res);
			location.reload();
		}
	});
}

function deleteComment(comm_id){
	$.ajax({
		url: './delete?comm_id=' + comm_id, // generateURL(2, 'delete', 'comm_id=' + comm_id), // 2 是 comment
		success: function(res){
			alert(res);
			location.reload();
		}
	});
}
</script>
</html>